
# 购物系统类
# 实例属性：
#     商品信息
#     系统说明信息
#     当前用户 -- 多个用户
# 方法：
#   登陆注册
#   查看商品
#   添加购物车
#   结算

# 用户类
# 实例属性：
#     用户名
#     密码
#     余额
#     购物车
# 方法：

class User():
    def __init__(self, name, passwd, init_amount):
        self.name = name
        self.passwd = passwd
        self.init_amount = init_amount
        self.shopping_car = {}


class ShoppingSystem:
    def __init__(self, goods_info, sys_info,):
        self.goods_info = goods_info
        self.sys_info = sys_info
        self.userdict = {}


    def register(self, name, passwd, initial_amount):
        # 创建一个新用户，实例化User类
        if name not in self.userdict:
            user = User(name, passwd, initial_amount)
        # 把名字作为key，user对象作为value 存在self.userdict里面
            self.userdict[name] = user
        else:
            print("用户已存在")
    def login(self, username, passwd):
        if username in self.userdict and passwd == self.userdict[name].passwd:
            print("登陆成功")
        else:
            print("登陆失败")
    def inquire(self,num):
        pass
        # for j in :
        #     print(f"{}")




fruit_goods = {
    '001':{ "name":"aapple", "price":8 },
    '002':{"name":"banana", "price":4},
}

medicine_goods ={
    'm001':{ "name":"奥司他韦","price":"100" },
    'm002':{ "name":"阿司匹林", "price":"50"},
}

system1 = ShoppingSystem(fruit_goods,"水果购买系统")
system2 = ShoppingSystem(medicine_goods,"药品购买系统")
system = [system1, system2]

while 1:
    print("当前平台，已有购物系统如下：")
    for k, v in enumerate(system):
        print(f"{k+1}.{v.sys_info}")
    c1 = input("请输入你的选择(按q退出)：")
    if c1 == "q":
        break
    if c1.isdigit() and int(c1) < len(system):
        c1 = int(c1)
        current_system = system[c1]
        print(f"欢迎进入{current_system.sys_info}".center(40, "*"))
        while 1:
            c2 = input("1.登录\n2.注册\n3.查询商品信息\n请输入你的选择(按q退出):")
            if c2 =="q":
                break
            if c2 == "1":
                username = input("请输入账号:")
                passwd = input("请输入密码:")
                current_system.login(username, passwd)
            elif c2 == "2":
                name, passwd, amount = input("请输入你的名字、密码、和初始金额(用空白分割)").split()
                current_system.register(name, passwd, amount)
                print(f"当前系统用户有:{current_system.userdict}")
            elif c2 == "3":
                print("请输入商品编号：")

                current_system.inquire()
            else:
                print("输入有误！")
    else:
        print("输入有误，请重新输入!")
